class Solution:
    def NumberOf1Between1AndN2(self, n):
        res = 0
        m = 1
        while m <= n:
            if ((n // m) % 10) >= 2:
                res += (n // 10 // m + 1) * m
            elif ((n // m) % 10) == 1:
                # 12100~12113,一共114个 从0开算 所以+1
                res += (n // 10 // m) * m + n % m + 1
            else:
                res += (n // 10 // m) * m
            m = m * 10
        return res


s = Solution()
print(s.NumberOf1Between1AndN2(10))